var express = require('express');
var fs = require('fs');
var path = require('path');
var router = express.Router();

/* GET home page. */
router.post('/saveFile', function(req, res, next) {
  console.log(req.body)
  let uuid = req.body.fileUUID;
  fs.writeFileSync(path.join(__dirname, `../saveFiles/${uuid}.json`), JSON.stringify(req.body));
  console.log('文件保存成功,');
res.json({
  message: 'ok',
  data: req.body
})
});

router.post('/saveMatlabFile', function(req, res, next) {
  console.log(req.body)
  let uuid = req.body.fileUUID;
  let nodeDataArray = req.body.nodeDataArray;
  let mContent = nodeDataArray.map(value => value.simulation)
  fs.writeFileSync(path.join(__dirname, `../matlab/${uuid}.m`), mContent);
  console.log('文件matlab保存成功,');
  res.json({
    message: 'ok',
    data: req.body
  })
});

module.exports = router;
